import { createStore } from "vuex";
import Cookies from 'js-cookie';

//全局变量默认城市
let defaultCity = "广州";
if(localStorage.city){
	//在localStorage中city存在时将值传给defaultCity
	defaultCity = localStorage.city;
}


export default createStore({
  state: {
	  on_line:false,//在线状态
	  cityName:defaultCity,
	  showLoading:false,//加载中弹窗
  },
  mutations: {
	  setCity(state,name){
	  		  state.cityName = name;
	  		  localStorage.city = name;
	  },
	  //用户已登录
	  onlogin(state){
		state.on_line = true;
	  },
	  //退出登录
	  outlogin(state){
		state.on_line = false;
	  },
	  //显示加载中
	  sload(state){
		state.showLoading = true;
	  },
	  //隐藏加载中
	  hload(state){
	  	setTimeout(()=>{state.showLoading=false},300);
	  }
  },
  getters:{
	  //验证在线状并将结果返回
	  hasOnline(state){
	  	state.on_line = (!localStorage.Online || localStorage.Online=='false' || localStorage.Online==undefined)?false:true;
		return state.on_line;
	  },
	  //图片缓存
	  getImg(state,url){
		  console.log(state,url);
		  return null;
	  	// if(url && url !== undefined){
	  	// 	let imgurl = url.substring(url.indexOf('https://')==0?8:7);
	  	// 	return 'https://images.weserv.nl/?url='+imgurl;
	  	// }
	  }
  },
  actions: {},
  modules: {},
});
